<template>
  <div>
    <el-dialog
      :title="'操作日志详情'"
      :visible.sync="dialogVisible"
      width="40%"
      @close="handleClose"
    >
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="12">
            <el-form-item label="操作模块：">{{ form.title }}</el-form-item>
            <el-form-item label="登录信息："
              >{{ form.operName }} / {{ form.operIp }} /
              {{ form.operLocation }}</el-form-item
            >
          </el-col>
          <el-col :span="12">
            <el-form-item label="请求地址：">{{ form.operUrl }}</el-form-item>
            <el-form-item label="请求方式：">{{
              form.requestMethod
            }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="操作方法：">{{ form.method }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="请求参数：">
              <json-viewer
                v-if="form.operParam"
                copyable
                theme="my-json-viewer-"
                :value="form.operParam"
                :expand-depth="2"
                boxed
                sort
              ></json-viewer>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="返回参数：">
              <json-viewer
                v-if="form.jsonResult"
                copyable
                theme="my-awesome-json-theme"
                :value="form.jsonResult"
                :expand-depth="5"
                boxed
                sort
              ></json-viewer>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="操作状态：">
              <div v-if="form.status === 0">正常</div>
              <div v-else-if="form.status === 1">失败</div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="消耗时间："
              >{{ form.costTime }}毫秒</el-form-item
            >
          </el-col>
          <el-col :span="8">
            <el-form-item label="操作时间：">{{ form.operTime }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="异常信息：" v-if="form.status === 1">{{
              form.errorMsg
            }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import JsonViewer from "vue-json-viewer";
import { getRegionDetail } from "@/api/system/errlog";
export default {
  name: "handleLog",

  components: {
    JsonViewer
  },
  filters: {
    businessTypeFilter(type) {
      const mapObj = {
        0: "其他",
        1: "新增",
        2: "修改",
        3: "删除",
        4: "授权",
        5: "导出",
        6: "导入",
        7: "强退",
        8: "生成代码",
        9: "清空数据",
        10: "爬虫"
      };
      returnmapObj[type];
    }
  },
  data() {
    return {
      form: {},
      dialogVisible: false
    };
  },
  created() {},
  methods: {
    handleClose() {
      this.dialogVisible = false;
    },
    openLog(v) {
      this.dialogVisible = true;
      this.handleDetail(v);
    },
    handleDetail(row) {
      getRegionDetail(row.operId).then(res => {
        if (res.data.jsonResult) {
          res.data.jsonResult = JSON.parse(res.data.jsonResult);
        }
        if (res.data.operParam) {
          res.data.operParam = JSON.parse(res.data.operParam);
        }
        this.form = res.data;
      });
    }
  }
};
</script>

<style scoped lang="scss"></style>
